package zheezes.protocol.impl.wt.du;

import java.util.Date;

import zheezes.protocol.impl.wt.DataUnit;
import zheezes.protocol.impl.wt.meta.FrzDate;


public class Ctrl9EDi0247DataUnit extends DataUnit {
	public static final int DATA_NUM = 27;
	
	private int seq = 0;
	private FrzDate[] list = new FrzDate[DATA_NUM];

	public Ctrl9EDi0247DataUnit() {
		for (int i = 0, n = list.length; i < n; i++) {
			list[i] = new FrzDate();
		}
	}

	public int sizeOfData() {
		int size = 1; // seq
		for (FrzDate f : list) {
			size += f.size();
		}
		return size;
	}

	@Override
	public int getData(byte[] buf, int offset) {
		int idx = offset;
		buf[idx++] = (byte) seq;
		for (FrzDate f : list) {
			idx += f.getBytes(buf, idx);
		}
		return idx - offset;
	}

	@Override
	public int setData(byte[] buf, int offset, int max) {
		int idx = offset;
		seq = buf[idx++];
		for (FrzDate f : list) {
			idx += f.setBytes(buf, idx, max);
		}
		return idx - offset;
	}

	public Date[] getDateList() {
		Date[] ds = new Date[list.length];
		for (int i = 0, n = list.length; i < n; i++) {
			ds[i] = list[i].getDate();
		}
		return ds;
	}
}
